import RobotError from "../errors/robot-error.js";
import Item from "../item/item.js";
import Prop from "../item/prop.js";
import Goods from "../shop/goods/goods.js";
import { CoinHolder, Fighter, ItemHolder, Purchaseable } from "./ability.js";
import CoinM from "./member/coin.js";
import ExpM from "./member/exp.js";
import FightM from "./member/fight.js";
import FightStatusM from "./member/fight_status.js";
import ItemM from "./member/item.js";
import PurchaseM from "./member/purchase.js";




export default class Player
	implements CoinHolder, Purchaseable, Fighter, ItemHolder {
	coinMember: CoinM = new CoinM(this, 0);
	fightMember: FightM = new FightM(this);
	purchaseMember: PurchaseM = new PurchaseM(this);
	expMember: ExpM = new ExpM(this);
	fightStatusMember: FightStatusM = new FightStatusM(this);
	itemMember: ItemM = new ItemM(this);

	qqNum: number;

	constructor() {
		// this.coinMember = new CoinM(this, 0);
		// this.fightMember = new FightM(this);
		// this.purchaseMember = new PurchaseM(this);
		// this.expMember = new ExpM(this);
		// this.fightStatusMember = new FightStatusM(this);
	}


	//TODO 待抽象化
	use(prop: Prop) {
		if (!this.hasItem(prop)) throw new RobotError("你没有" + prop.name);
		this.removeItem(prop, 1);
		return prop.use(this);
	}

	addItem(item: Item, num?: number): void {
		this.itemMember.addItem(item, num);
	}
	removeItem(item: Item, num?: number): void {
		this.itemMember.removeItem(item, num);
	}
	hasItem(item: Item): boolean {
		return this.itemMember.hasItem(item);
	}
	itemCount(item: Item): number {
		return this.itemMember.itemCount(item);
	}
	get items() {
		return this.itemMember.items;
	}

	name: string = "无名氏";

	get nick(): string {
		return this.name;
	}
	set nick(nick) {
		this.name = nick;
	}


	get totalExp() {
		return this.expMember.totalExp;
	}
	set totalExp(value) {
		this.expMember.totalExp = value;
	}
	get exp(): number {
		return this.expMember.exp;
	}
	set exp(exp: number) {
		this.expMember.exp = exp;
	}

	get maxExp() {
		return this.expMember.maxExp;
	}

	get level() {
		return this.expMember.level;
	}

	get hpRatio() {
		return this.fightStatusMember.hpRatio;
	}
	set hpRatio(value) {
		this.fightStatusMember.hpRatio = value;
	}
	get maxHp() {
		return this.fightStatusMember.maxHp;
	}
	get currentHp() {
		return this.fightStatusMember.currentHp;
	}
	set currentHp(hp) {
		this.fightStatusMember.currentHp = hp;
	}

	get attackPower() {
		return this.fightStatusMember.attackPower;
	}

	get defensivePower() {
		return this.fightStatusMember.defensivePower;
	}

	get agility() {
		return this.fightStatusMember.agility;
	}

	/**@implements {CoinHolder} */
	get coin(): number {
		return this.coinMember.value;
	}
	set coin(coin: number) {
		this.coinMember.value = coin;
	}

	/**@implements {Purchaseable} */
	buy(goods: Goods, num: number = 1) {
		return this.purchaseMember.purchase(goods, num);
	}

	/**@implements {Fighter} */
	damageTo(target: Fighter): number {
		return this.fightMember.damageTo(target);
	}

	dodgeProbability(attacker: Fighter): number {
		return this.fightMember.dodgeProbability(attacker);
	}

	dodgeSuccess(attacker: Fighter): boolean {
		return this.fightMember.dodgeSuccess(attacker);
	}

	hit(target: Fighter) {
		return this.fightMember.hit(target);
	}

	hurt(target: Fighter) {
		return this.fightMember.hurt(target);
	}

	isAlive(): boolean {
		return this.fightMember.isAlive();
	}

	reborn(): void {
		return this.fightMember.reborn();
	}

	suicide(): void {
		return this.fightMember.suicide();
	}
}
